<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="title">
            <h:outputText value="Create Purchase Order"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <h:form rendered="#{loginBacking.addPurchaseOrder}">
                <p:panel header="Create Purchase Order">
                    <p:messages />
                    <br />
                    <h:panelGrid columns="4">
                        <h:outputLabel value="Sales Quotation Id:" for="salesQuotation" />
                        <p:inputText id="salesQuotation" value="#{purchaseOrderEntityController.selected.salesQuotation}" title="#{bundle.CreatePurchaseOrderEntityTitle_salesQuotation}" readonly="true"/>
                        <h:message styleClass="errorMsg" for= "salesQuotation" />
                        <h:outputText value=" " rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>

                        <h:outputLabel value="Sales Lead:" rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>
                        <p:inputText id="salesLead" value="#{purchaseOrderEntityController.selected.salesLead}" title="#{bundle.CreatePurchaseOrderEntityTitle_customer}" readonly="true" rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>
                        <h:message styleClass="errorMsg" for= "salesLead" />

                        <h:outputText value=" " rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>
                        <h:outputLabel value="Assign Sales Executive:" rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>
                        <h:selectOneMenu id="customerExecutive" value="#{purchaseOrderEntityController.salesExecutive}" rendered="#{purchaseOrderEntityController.selected.salesLead!=null}" title="#{bundle.ConvertSalesLeadEntityTitle_customerExecutive}" >
                            <f:validator validatorId="macTeam.SystemUserSelectOneMenuValidator" />
                            <f:selectItems value="#{systemUserEntityController.salesExecutiveAvailableSelectOne}" />
                        </h:selectOneMenu>
                        <h:message styleClass="errorMsg" for= "customerExecutive" rendered="#{purchaseOrderEntityController.selected.salesLead!=null}"/>

                        <h:outputLabel value="#{bundle.CreatePurchaseOrderEntityLabel_customer}" for="customer" rendered="#{purchaseOrderEntityController.selected.customer!=null}"/>
                        <p:inputText id="customer" value="#{purchaseOrderEntityController.selected.customer}" title="#{bundle.CreatePurchaseOrderEntityTitle_customer}" readonly="true" rendered="#{purchaseOrderEntityController.selected.customer!=null}"/>
                        <h:message styleClass="errorMsg" for= "customer" />
                    </h:panelGrid>
                    <br />
                    <p:separator />
                    <br />
                    <p:fieldset legend="Customer Preference">
                        <h:outputLabel value="Please indicate your preferred shipping date:" for="preferredLeadTime" /><p:spacer width="50" height="10" />
                        <p:calendar id="preferredLeadTime" value="#{purchaseOrderEntityController.selected.preferredLeadTime}" mindate="#{purchaseOrderEntityController.getToday()}" title="#{bundle.CreatePurchaseOrderEntityTitle_preferredLeadTime}" />
                    </p:fieldset>
                    <br />
                    <h:panelGrid columns="5">
                        <h:outputLabel value="Product:" style="font-weight:bold"/>
                        <h:outputLabel value="Quantity:" style="font-weight:bold"/>
                        <h:outputLabel value="Price Per Unit (S$)" style="font-weight:bold"/>
                        <h:outputLabel value="Sub Total Price (S$)" style="font-weight:bold"/>
                        <h:outputLabel value=""/>

                        <h:outputLabel value="Classic Nutri Bar (Nuts)" />
                        <p:inputText id="quantity" binding="#{quantity1}" value="#{purchaseOrderEntityController.selectedPQP.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" >
                            <p:ajax event="keyup" update="price and pricepu"   
                                    listener="#{purchaseOrderEntityController.calculatePQP}"/>  
                        </p:inputText>
                        <h:outputText id="pricepu" value="#{purchaseOrderEntityController.selectedPQP.pricePerUnit}" />
                        <h:outputText id="price" value="#{purchaseOrderEntityController.selectedPQP.price}" />
                        <h:outputLabel value=""/>

                        <h:outputLabel value="Classic Nutri Bar (Fruits)" />
                        <p:inputText id="quantity2" binding="#{quantity2}" value="#{purchaseOrderEntityController.selectedPQP2.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" >
                            <p:ajax event="keyup" update="price2 and pricepu2"   
                                    listener="#{purchaseOrderEntityController.calculatePQP2}"/>  
                        </p:inputText>
                        <h:outputText id="pricepu2" value="#{purchaseOrderEntityController.selectedPQP2.pricePerUnit}" />
                        <h:outputText id="price2" value="#{purchaseOrderEntityController.selectedPQP2.price}" />
                        <h:outputLabel value=""/>

                        <h:outputLabel value="Premium Power Bar (Chocolate Nuts)" />
                        <p:inputText id="quantity3" binding="#{quantity3}" value="#{purchaseOrderEntityController.selectedPQP3.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" >
                            <p:ajax event="keyup" update="price3 and pricepu3"   
                                    listener="#{purchaseOrderEntityController.calculatePQP3}"/>  
                        </p:inputText>
                        <h:outputText id="pricepu3" value="#{purchaseOrderEntityController.selectedPQP3.pricePerUnit}" />
                        <h:outputText id="price3" value="#{purchaseOrderEntityController.selectedPQP3.price}"/>
                        <h:outputLabel value=""/>

                        <h:outputLabel value="Premium Power Bar (Redcurrant Fruits)" />
                        <p:inputText id="quantity4" value="#{purchaseOrderEntityController.selectedPQP4.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" >
                            <p:ajax event="keyup" update="price4 and pricepu4"   
                                    listener="#{purchaseOrderEntityController.calculatePQP4}"/>  
                            <f:validator validatorId="macTeam.ProductQuantityInputValidator"/>
                            <f:attribute name="quantity1" value="#{quantity1.value}" />
                            <f:attribute name="quantity2" value="#{quantity2.value}" />
                            <f:attribute name="quantity3" value="#{quantity3.value}" />
                        </p:inputText>
                        <h:outputText id="pricepu4" value="#{purchaseOrderEntityController.selectedPQP4.pricePerUnit}" />
                        <h:outputText id="price4" value="#{purchaseOrderEntityController.selectedPQP4.price}" />
                        <h:message styleClass="errorMsg" for= "quantity4" />
                    </h:panelGrid>
                </p:panel>
                <br />
                <ui:include src="/entities/shippingRequestEntity/EditShippingRequests.xhtml" />
                <br />
                <p:panel header="Payment Information">
                    <h:panelGrid columns="3">
                        <h:outputLabel value="Payment Method:" for="paymentMethod" />
                        <h:selectOneMenu id="paymentMethod" value="#{purchaseOrderEntityController.selected.paymentMethod}" >
                            <f:selectItems value="#{purchaseOrderEntityController.paymentMethod}"/>
                        </h:selectOneMenu>
                        <h:message styleClass="errorMsg" for= "paymentMethod" />

                        <h:outputLabel value="Billing Address:" for="billingAddress" />
                        <h:selectOneMenu id="billingAddress" value="#{purchaseOrderEntityController.selected.billingAddress}" >
                            <f:selectItems value="#{addressEntityController.billingAddressesAvailableSelectOne}"/>
                            <f:validator validatorId="macTeam.AddressSelectOneMenuValidator"/>
                        </h:selectOneMenu>   
                        <h:message styleClass="errorMsg" for= "billingAddress" />
                    </h:panelGrid>
                </p:panel>
                <br />
                <p:commandButton ajax="false" action="#{purchaseOrderEntityController.create}" value="#{bundle.CreatePurchaseOrderEntitySaveLink}" />
                &nbsp;
                <p:commandButton ajax="false" action="#{purchaseOrderEntityController.prepareList}" value="Show All Purchase Orders" immediate="true"/>
                <br />
                <br />
            </h:form>
        </ui:define>
    </ui:composition>

</html>
